import { get, post, put, del } from '@/utils/request';
import type { Menu } from '@/types';

/**
 * 菜单相关API
 */

// 获取用户菜单（根据权限）
export const getUserMenus = () => {
  return get<Menu[]>('/menus/user-menus');
};

// 获取用户按钮权限
export const getUserButtons = () => {
  return get<Array<{ name: string; permission: string }>>('/menus/user-buttons');
};

// 获取菜单树
export const getMenuTree = () => {
  return get<Menu[]>('/menus/tree');
};

// 获取菜单列表
export const getMenuList = () => {
  return get<Menu[]>('/menus');
};

// 获取菜单详情
export const getMenuDetail = (id: string) => {
  return get<Menu>(`/menus/${id}`);
};

// 创建菜单
export const createMenu = (data: Partial<Menu>) => {
  return post<Menu>('/menus', data);
};

// 更新菜单
export const updateMenu = (data: Partial<Menu> & { id: string }) => {
  const { id, ...rest } = data;
  return put<Menu>(`/menus/${id}`, rest);
};

// 删除菜单
export const deleteMenu = (id: string) => {
  return del(`/menus/${id}`);
};

